<?php
/**
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2018/8/1
 * Time: 11:26
 */
namespace app\api\validate;

use think\Validate;

class SupplierInfo extends Validate
{
    protected $rule = [
        'name|名称'  =>  'require|max:30',
        //'tel|电话'  =>  'check_tel',
        'phone|手机号' =>  'require|mobile',
        'supplier_type_ids' =>  'require',
        'main' =>  'require',
        'intro|企业概况' =>  'max:1500',
        'province' =>  'require|number|gt:0',
        'city' =>  'require|number|gt:0',
        'district' =>  'require|number|gt:0',
        'address|详细地址' =>  'require|min:3',
        'lng' =>  'require',
        'lat' =>  'require',
        'headimg|商家LOGO' =>  'url',
        'grade_id' =>  'require|integer|gt:0',
        'code|微信CODE' =>  'require',
    ];

    protected $message  =   [
        'supplier_type_ids.require' => '至少选择一项行业',
        'main.require' => '至少选择一项主营业务',
        'province.require' => '省份不能为空',
        'province.number' => '省份格式不正确',
        'province.gt' => '省份格式不正确',
        'city.require' => '城市不能为空',
        'city.number' => '城市格式不正确',
        'city.gt' => '城市格式不正确',
        'district.require' => '区县不能为空',
        'district.number' => '区县格式不正确',
        'district.gt' => '区县格式不正确',
        'lng.require' => '位置获取失败',
        'lat.require' => '位置获取失败',
        'grade_id.require' => '入驻方式不能为空',
        'grade_id.integer' => '入驻方式格式不正确',
        'grade_id.gt' => '入驻方式格式不正确',
    ];

    //检查电话是否合法
    protected function check_tel($value)
    {
        $isTel="/^([0-9]{3,4}-)?[0-9]{7,8}$/";
        if(!preg_match($isTel,$value))
        {
            return '电话格式不正确';
        }
        return true;
    }
    public function sceneEdit()
    {
        return $this->remove('grade_id')
            ->remove('code');
    }
}